$(function(){
	//界面初始化
	initView();	
});
function initView(){
	var managerSearch ={};
	managerSearch.phName   ="";	
	managerSearch.insName  ="";
	managerSearch.status   ="";
	managerSearch.preprintedNo ="";
	managerSearch.orderId ="";
	managerSearch.policyRef ="";
	managerSearch.createDateFrom ="";
	managerSearch.createDateTo ="";
	var manager = JSON.parse(getQueryString("data"));
	if(manager){
		handleQuey(manager);
		managerSearch=manager;
	}
	managerSearch.sortDir ="desc";
	managerSearch.updateDateFrom ="";
	managerSearch.updateDateTo ="";
	managerSearch.sortField ="";
	padMarketing.ajaxNormal(
			"/pad_marketing/ordermanager/search.action",
			managerSearch,
			function (data){
				handleData(data);	
			},
			function(data){},
			true,
			true,
			"系统正在查询您名下订单，请耐心等待"
	);

}
function search(){	
	var start =$("input[name='createDateFrom']").val();
	var end =$("input[name='createDateTo']").val();
	if(new Date(end).getTime()-new Date(start).getTime() <0){
		alertMsg("起始日期不能大于结束日期");
		return;
	}
	closeDiv('open1');
	$("#orderManagerLi").html("");
	var managerSearch =$("#selectForm").serializeObject();
	padMarketing.ajaxNormal(
			"/pad_marketing/ordermanager/search.action",
			managerSearch,
			function (data){
				handleData(data);	
			},
			function(data){},
			true,
			true,
			"系统正在查询您名下订单，请耐心等待"
	);
}
function handleData(json){
	var stateArr =["S","U","P","I","F","O","C"];
	var html="";
	for(var j in stateArr){
		for(var i in json)
		{				
			if(json[i].status==stateArr[j]){
				var app = json[i];				
				html+="<li orderId ='"+app.orderId+"' status ='"+app.status+"'>";
				html+="<div class='img-box'>";
		        
		         html+=   "<img src=\'/portal/resources/images/product/SJ_"+ app.productId +".jpg\'>";
		         if(app.status=="F"){
		        	 html+=   "<label class='sort sort-success'><i>已支付</i></label>";
		         }else if(app.status=="P"){
		        	 html+=   "<label class='sort sort-danger'><i>待支付</i></label>";
		         }else if(app.status=="O"){		        	
		        	 html+=   "<label class='sort sort-warning'><i>人工核保</i></label>";
		         }else if(app.status=="C"){
		        	 html+=   "<label class='sort sort-gray'><i>已撤单</i></label>";
		         }else if(app.status=="I"){
		        	 html+=   "<label class='sort sort-purple'><i>录入中</i></label>";
		         }else if(app.status=="U"){
		        	 html+=   "<label class='sort sort-info'><i>待拍照</i></label>";
		         }else if(app.status=="S"){
		        	 html+=   "<label class='sort sort-primary'><i>待签名</i></label>";
		         }
		         
		         html+=   "</div>";
		         html+=   "<h3 class='p-overflow'>"+HtmlEncode(app.phName+" "+app.orderId)+"</h3>";
		         html+=   "<div class='show'>";
		         html+=   "<div class='popover-panel hide'>";
		         html+=   "<i class='popover-sort'></i>";
		         
		         if(app.status!="I"){
		        	 html+=   "<a  onclick='lookManager(this,1)' class='text-center'>";
			         html+=   " <p class='icon icon-circle-view'></p>";
			         html+=   "  <p class='purple font-14'>只读</p>";
			         html+=   "</a>";
		         }		         
		         if(app.status=="S"){
		        	 html+=   "<a  onclick='writeName(this,1)' class='text-center'>";
			         html+=   " <p class='icon icon-sign'></p>";
			         html+=   " <p class='blue-d font-14'>签名</p>";
			         html+=   "</a>";
		         } 
		         if(app.status=="U"){
		        	 html+=   "<a  onclick='takePhotoM(this,1)' class='text-center'>";
			         html+=   " <p class='icon icon-photo'></p>";
			         html+=   " <p class='yellow font-14'>拍照</p>";
			         html+=   "</a>";
		         } 
		         if(app.allowPayment=="Y"&&app.salesTool=="APP"){
		        	 html+=   "<a  onclick='payMoney(this,1)' class='text-center'>";
			         html+=   " <p class='icon icon-circle-pay'></p>";
			         html+=   " <p class='green font-14'>支付</p>";
			         html+=   "</a>";
		         }
		         if(app.allowContinue=="Y"&&app.salesTool=="APP"){
		        	 html+=   "<a  onclick='changeManager(this,1)' class='text-center'>";
			         html+=   " <p class='icon icon-jxtb'></p>";
			         html+=   " <p class='blue-l font-14'>继续投保</p>";
			         html+=   "</a>";
		         } 
		         if(app.allowDel=="Y"&&app.salesTool=="APP"){
		        	 html+=   "<a onclick='deleteManager(this,1)'  class='text-center'>";
			         html+=   " <p class='icon icon-remove-sm'></p>";
			         html+=   " <p class='red font-14'>删除</p>";
			         html+=   "</a>";
		         } 
		        if(app.allowCbi=="Y"&&app.salesTool=="APP"){
		        	html+=   "<a class='text-center'>";
			        html+=   " <p class='icon icon-circle-edit sm'></p>";
			        html+=   " <p class='blue font-14'>撤单</p>";
			        html+=   "</a>";
		        }
		        html+=   "<a onclick='copyManager(this,1)' class='text-center'>";
		         html+=   "  <p class='icon icon-circle-copy'></p>";
		         html+=   "  <p class='orange font-14'>复制</p>";
		         html+=   "</a>";
		         html+=   "</div>";
		         html+=   "</div>";
		         html+=   "<div class='check-list hide'>";
		         html+=   "<input type='checkbox'>";
		         html+=   "<label for=''>&nbsp;</label>";
		         html+=   "</div>";
		         html+=   "</li>";		         		         
			}			
		}
		html+=   "<div>";
        html+=   "</div>";
}
	$("#orderManagerLi").append(html);
	$("li").each(function(index,me){
		var orderId = $(me).attr("orderId");
		for(var k in json){
			var app = json[k];
			if(orderId==app.orderId){
				$(me).data("data",app);
			}
		}
		
	});
	$(".bookshelf").popover();
	if(myScroll)
		myScroll.refresh(); 
}

padMarketing.ajaxNormal("/pad_marketing/main/getUser.action", {},
		function(data) {
			if(data.username.cityCode == 370600){
				$("#jg").show();
				}
		}, function(data) {
			
		})
function switchHtml(type){
	var managerSearch =$("#selectForm").serializeObject();
	location.href="/pad_marketing/ordermanager/"+type+".action?data="+encodeURIComponent(JSON.stringify(managerSearch));
}
function handleQuey(managerSearch){
	$('#selectForm').formEdit(managerSearch);
}
function changePayMoney(me,index){
	window.location.href="/pad_marketing/main/editPay.action?url=ordermanager/"+orderManager(index)+".action";
}
function payMoneyHref(me,index){
	window.location.href="/pad_marketing/main/pay.action?url=ordermanager/"+orderManager(index)+".action";
}